// This file is part of OpenMeca, an easy software to do mechanical simulation.
//
// Author(s)    :  - Damien ANDRE  <openmeca@gmail.com>
//
// Copyright (C) 2012 Damien ANDRE
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.


#ifndef OpenMeca_Core_System_hpp
#define OpenMeca_Core_System_hpp

#include <sstream>
#include <vector>
#include "OpenMeca/Core/SetOf.hpp"
#include "OpenMeca/Core/AutoRegister.hpp"
#include "OpenMeca/Core/HistoricManager.hpp"
#include "OpenMeca/Core/SystemSettings.hpp"

namespace OpenMeca
{

  namespace Core
  {
    class UserItem;
    class UserRootItem;

    class System
    {
  
    public:

      static System& Get();
      static void Quit();
      static bool IsDeleted();

      ~System();
   
      template<class T> SetOf<T>& GetSetOf();
      template<class T> const SetOf<T>& GetSetOf() const;

      bool IsEdited();
      void Update();
      std::string GetAutomaticName(const std::string&) const;
      void SaveFile(std::string&);
      void LoadFile(std::string&);
      void Reset();
      HistoricManager& GetHistoric();
      const HistoricManager& GetHistoric() const;
      void Save(std::string&);
      void Load(std::string&);
      void Draw() const;
      void DrawWithNames() const;

      SystemSettings& GetSettings();
      const SystemSettings& GetSettings() const;

    private :
      System();                          //Not Allowed
      System(const System&);             //Not Allowed
      System& operator=(const System&);  //Not Allowed

    private :
      static System* activeSystem_;
      static bool deleted_;

    private :
      SystemSettings settings_;
      HistoricManager historic_; //Always at the end !
    }; 
    

    template<class T>  
    inline SetOf<T>&
    System::GetSetOf()
    {
      return AutoRegister<T>::GetGlobalSet();
    }

    template<class T>  
    inline const SetOf<T>&
    System::GetSetOf() const
    {
      return AutoRegister<T>::GetGlobalSet();
    }

  
  }
}
#endif
